package com.woniu.airent.controller;

import com.woniu.airent.entity.House;
import com.woniu.airent.service.impl.SearchMapServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("map")
public class SearchMapController {
    @Autowired
    SearchMapServiceImpl searchMapServiceImpl;

    @RequestMapping("/areaCheck")
    public String areaCheck(Model model, String areaName, String money, String area, String house, HttpServletRequest request){
        if(money!=""&&money!=null){
            money=money.substring(0,money.length()-1).replace("-",",");
        }else{
            money="0";
        }
        if(area!=""&&area!=null){
            area=area.substring(0,area.length()-1).replace("-",",");
        }else{
            area="0";
        }
        if(house!=""&&house!=null){
            house=house.substring(0,house.length()-1);
        }else{
            house=null;
        }

        String[] areas = area.split(",");
        //String[] houses = house.split(",");
        String[] moneys = money.split(",");
        List<House> houseList = searchMapServiceImpl.findHouseByMap(areaName,house,moneys,areas);
        model.addAttribute("houses",houseList);
        model.addAttribute("areaName",areaName);
        request.getSession().setAttribute("areaName",areaName);
        return "view/searchmap";
    }
}
